package com.hhf.demo_04;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @Author: 黄恒锋
 * @DateTime: 2024/5/11 20:40
 * @Description: 面条
 */
public class Cook extends Thread{
    ArrayBlockingQueue<String> queue;

    int sum = 100;
    public Cook(ArrayBlockingQueue<String> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true){
            // 不断的吧面条放到堵塞队列中
            try {
                if(sum == 0){
                    break;
                }else {
                    queue.put("面条");
                    System.out.println("厨师放了一碗面条");
                    sum --;
                }

            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
